package vno.fux.map
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.aswing.Container;
	
	import vno.fux.BaseDisplayObject;
	import vno.fux.BasePoint;
	import vno.fux.res.manager.ResourceManager;
	import vno.fux.res.pool.MapTile;
	import vno.fux.res.pool.ResourcePool;
	import vno.fux.ui.WalkTarget;
	import vno.fux.events.MapEvent;
	
	
	public class MapView extends BaseMapView
	{
		private var _mapView:Sprite;
		//private var _children:Array;
		public function MapView(model_:MapModel, controller_:MapController)
		{
			super(model_, controller_);
			//_children = new Array();
			_mapView = new Sprite;
			//initBackGroundView();
			initThumbMapView();
			initMapTilesView();
			//initGridView();
			
			this.content = _mapView;
			this.addEventListener(MouseEvent.CLICK, _controller.handleClick);
//			this.addEventListener(MouseEvent.CLICK, handleClick);
		}
		
		protected function handleClick(event:MouseEvent):void
		{
			trace(event);
		}
		
		private function initBackGroundView():void
		{
			var view:BaseMapView = new BackGroundView(this._model, this._controller);
			//_children.push(view);
			_mapView.addChild(view);
		}
		private function initThumbMapView():void
		{
			var view:BaseMapView = new ThumbMapView(this._model, this._controller);
			//_children.push(view);
			_mapView.addChild(view);
		}
		private function initMapTilesView():void
		{
			var view:BaseMapView = new MapTilesView(this._model, this._controller);
			view.name = MapTilesView.NAME;
			//_children.push(view);
			_mapView.addChild(view);
		}
		private function initGridView():void
		{
			var view:BaseMapView = new GridView(this._model, this._controller);
			_mapView.addChild(view);
		}
		override public function update(evt:Event):void
		{
//			for each (var child:BaseMapView in _children)
//			{
//				child.update(evt);
//			}
		}
		
		public function stimulateClick(event_:MapEvent):void
		{
			//trace(event_);
//			var event = new MouseEvent(event_.type,false,false,event_.localX,event_.localY);
//			//trace(event);
			(_mapView.getChildByName(MapTilesView.NAME) as BaseDisplayObject).content.dispatchEvent(new MouseEvent(MouseEvent.CLICK,true,false,event_.pos.x,event_.pos.y));
		}
	}
}